window.onload=function(){
    layui.use(['jquery','layer'],function(){
        var $ = layui.jquery;

        var pswdStr=`<div class="layui-form">
                        <div class="layui-form-item">
                        <label class="layui-form-label">当前密码</label>
                        <div class="layui-input-inline">
                            <input type="password" class="layui-input old_pwd">
                        </div>
                        </div>
                        <div class="layui-form-item">
                        <label class="layui-form-label">新密码</label>
                        <div class="layui-input-inline">
                            <input type="password" class="layui-input pwd">
                        </div>
                        </div>
                        <div class="layui-form-item">
                        <label class="layui-form-label">确认新密码</label>
                        <div class="layui-input-inline">
                            <input type="password" class="layui-input re_pwd">
                        </div>
                        </div>
                        <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn qr">确认修改</button>
                        </div>
                        </div>
                    </div>`

        $(".modify-pwd").on("click",function(){
            Utils.layer.open({
                type:1,
                title:'修改密码',
                content:pswdStr,
            })
            $(".qr").on("click",function(){
                var old_pwd=$(".old_pwd").val();
                var pwd=$(".pwd").val();
                var re_pwd=$(".re_pwd").val();
                if(old_pwd==""||pwd==""||re_pwd==""){
                    layer.msg("请完善信息")
                }else if(pwd!=re_pwd){
                    layer.msg("两次密码输入不一致")
                }else{
                    $.ajax({
                        url:"/admin/modify-pwd",
                        type:"post",
                        data:{old_pwd:old_pwd,pwd:pwd,re_pwd:re_pwd},
                        success: function(data) {
                            if(data.code==200){
                                Utils.layer.msg(data.msg);
                                setTimeout(function(){
                                    location.href="/admin/login";
                                }, 1000);
                            }else{
                                Utils.layer.msg(data.msg);
                            }
                        }
                    })
                }
            });
        });
    });
};